<template>
  <Portlet :title="innerTitle">
    <template slot="tools">
      <el-button v-if="changePassword" type="primary" @click.prevent="isChangePassword = !isChangePassword">
        {{ isChangePassword ? '返回' : '修改密码' }}
      </el-button>
      <el-button v-if="isEdit" type="primary" @click.prevent="toEditing">修改</el-button>
    </template>
    <ChangePassword @update="isChangePassword = false" :data="data" v-if="isChangePassword"></ChangePassword>
    <el-form v-else label-position="left" label-width="120px">
      <el-row class="row">
        <el-col :lg="8" :md="12" :xl="6">
          <el-form-item label="绑定登陆手机号:">
            <span>{{ data.phone }}</span>
          </el-form-item>
        </el-col>
        <el-col :lg="8" :md="12" :xl="6">
          <el-form-item label="姓名:">
            <span>{{ data.name }}</span>
          </el-form-item>
        </el-col>
        <el-col :lg="8" :md="12" :xl="6">
          <el-form-item label="岗位:">
            <span>{{ data.position }}</span>
          </el-form-item>
        </el-col>
        <el-col :lg="8" :md="12" :xl="6">
          <el-form-item label="角色名称:">
            <span>{{ data.roleName }}</span>
          </el-form-item>
        </el-col>
        <el-col :lg="8" :md="12" :xl="6">
          <el-form-item label="所属公司编号:">
            <span>{{data.companyCode}}</span>
          </el-form-item>
        </el-col>
        <el-col :lg="8" :md="12" :xl="6">
          <el-form-item label="所属公司名称:">
            <span>{{data.companyName}}</span>
          </el-form-item>
        </el-col>
        <el-col :lg="8" :md="12" :xl="6">
          <el-form-item label="状态:">
            <span>{{ data.state == 1 ? '启用' : '停用'}}</span>
          </el-form-item>
        </el-col>
        <el-col :lg="8" :md="12" :xl="6">
          <el-form-item label="创建人:">
            <span>{{data.founderUserName}}</span>
          </el-form-item>
        </el-col>
        <el-col :lg="8" :md="12" :xl="6">
          <el-form-item label="创建时间:">
            <span>{{data.foundDate | unixTimestampFilter}}</span>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div class="clearfix"></div>
  </Portlet>
</template>
<script>
import ChangePassword from '@/views/oms/user/ChangePassword'
import {unixTimestampFilter} from '@/filters'

export default {
  components: {
    ChangePassword
  },
  filters: {
    unixTimestampFilter
  },
  props: {
    data: {
      type: Object,
      default() {
        return {}
      }
    },
    title: {
      type: String,
      default: '基本信息'
    },
    changePassword: {
      type: Boolean,
      default: false
    },
    isEdit: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    innerTitle() {
      if (this.isChangePassword) {
        return '修改登录密码'
      }
      return this.title
    },
    userId() {
      return this.data.userId
    }
  },
  data() {
    return {
      isChangePassword: false,
      routeName: this.$route.name
    }
  },
  methods: {
    toEditing() {
      console.log(this.routeName)
      if (this.routeName === 'userShow') {
        this.$router.push({path: '/ss-oms/user/create/' + this.userId})
      } else {
        this.$router.push({path: '/ss-oms/info/user/create/' + this.userId})
      }
    }
  }
}
</script>
